using UnityEngine;
using System.Collections;

public class Scratch : MonoBehaviour {
	
	private const float TILT_SPEED = 500.0f; 
	private const float MAX_TILT   = 15.0f * Mathf.Deg2Rad;
	private bool tiltingUp;
	private bool tiltingDown;
	private bool returning;
	
	// Use this for initialization
	void Start () {
	}

	void Update() {
		print (rigidbody.angularVelocity.z);
	}
	
	void FixedUpdate() {
		
		bool upAction = Input.GetKey (KeyCode.UpArrow);
		bool dnAction = Input.GetKey (KeyCode.DownArrow);
		
		
		
		/*
		if(upAction && !tiltingUp) {
			rigidbody.AddTorque(Vector3.forward * TILT_SPEED);
			tiltingUp = true;
		} else if(dnAction && !tiltingDown) {
			rigidbody.AddTorque(Vector3.forward * (-1 * TILT_SPEED));
			tiltingDown = true;
		} else if(!upAction && !dnAction && !returning && rigidbody.rotation.z != 0) {
			rigidbody.AddTorque(Vector3.forward * (TILT_SPEED * ((rigidbody.rotation.z > 0) ? -1 : 1)));
			returning = true;
			tiltingUp = tiltingDown = false;
		}
		*/
		
		//if(returning && (rigidbody.rotation.z < 1.0 || rigidbody.rotation.z > -1.0)) {
		//	rigidbody.rotation = Quaternion.AngleAxis(0, Vector3.forward);
		//	returning = false;
		//}
		/*
		if(IsMaxTilt() || IsMinTilt()) {
			rigidbody.angularVelocity = Vector3.zero;
		}
		if(Input.GetKey(KeyCode.UpArrow) ^ headTiltUp) {
			headTiltUp = !headTiltUp;
			rigidbody.AddTorque(Vector3.forward * ((headTiltUp ? 1 : -1) * TILT_SPEED * Mathf.Deg2Rad));
		}
		if(Input.GetKey(KeyCode.DownArrow) ^ headTiltDown) {
			headTiltDown = !headTiltDown;
			//rigidbody.AddTorque(Vector3.forward * ((headTiltDown ? -1 : 1) * TILT_SPEED * Mathf.Deg2Rad));
		}
		*/
		//rigidbody.AddRelativeForce (Vector3.right * 100 - rigidbody.velocity);
	}
}